package com.example.carefree_server.controller.c_departmentController;

import com.example.carefree_server.entity.Activity;
import com.example.carefree_server.entity.Result;
import com.example.carefree_server.exception.AlreadyExistsException;
import com.example.carefree_server.service.s_departmentService.signInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/signIn")
public class signInController {

    @Autowired
    private signInService signInService;

    // 签到数据插入
    @PostMapping("/dataAdd")
    public Result dataAdd(@RequestBody @Validated Activity activity) {
        try {
            if (activity != null) {
                signInService.dataAdd(activity);
                return Result.success();
            } else {
                return Result.error("不能插入空数据");
            }
        } catch (AlreadyExistsException e) {
            return Result.error(e.getMessage());
        }
    }
}
